package com.xuecheng.manage_cms.controller;

import com.xuecheng.api.cms.CmsTemplateControllerApi;
import com.xuecheng.framework.domain.cms.CmsTemplate;
import com.xuecheng.framework.domain.cms.request.QueryPageRequest;
import com.xuecheng.framework.domain.cms.request.QueryTemplateRequest;
import com.xuecheng.framework.domain.cms.response.CmsTemplateResult;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_cms.service.CmsTemplateService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhaoxiang
 * @version 1.0
 * @Date 2019/10/4 21:00
 */
@RestController
@RequestMapping("/cms/template")
public class CmsTemplateController implements CmsTemplateControllerApi {

    @Autowired
    private CmsTemplateService cmsTemplateService;

    @Override
    @ApiOperation("分页查询页面列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true,paramType = "path",dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页记录", required = true,paramType = "path",dataType = "int"),

    })
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findList(@PathVariable("page") int page, @PathVariable("size") int size, QueryTemplateRequest queryTemplateRequest) {
        return cmsTemplateService.findList(page, size, queryTemplateRequest);
    }

    @Override
    @PostMapping("/add")
    @ApiOperation("新增页面")
    public CmsTemplateResult add(@RequestBody CmsTemplate cmsTemplate) {
        return cmsTemplateService.add(cmsTemplate);
    }

    @Override
    @GetMapping("/get/{id}")
    @ApiOperation("根据pageId查询页面信息")
    public CmsTemplate findByTemplateId(@PathVariable("id") String templateId) {
        return cmsTemplateService.findByTemplateId(templateId);
    }

    @Override
    @PutMapping("/edit/{id}")
    @ApiOperation("修改页面")
    public CmsTemplateResult edit(@PathVariable("id") String templateId, @RequestBody CmsTemplate cmsTemplate) {
        return cmsTemplateService.update(templateId, cmsTemplate);
    }

    @Override
    @DeleteMapping("/del/{id}")
    @ApiOperation("删除页面")
    public ResponseResult delete(@PathVariable("id") String templateId) {
        return cmsTemplateService.delete(templateId);
    }

    @Override
    @GetMapping("/selectSiteList")
    @ApiOperation("站点下拉菜单列表")
    public QueryResponseResult findSiteList() {
        return cmsTemplateService.findSiteList();
    }

}
